package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.db.domain.MarketKeyword;
import com.cskaoyan.market.service.wx.WxSearchService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.HistoryKeyWord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/20 11:05
 */
@RestController
@RequestMapping("/wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;
    @GetMapping("index")
    public Object index(){
//        List<Map<String,String>> historyKeywordMap=wxSearchService.indexHistoryWord();
        List<HistoryKeyWord> historyKeywordMap=wxSearchService.indexHistoryWord();
        Map<String, List<MarketKeyword>> map=wxSearchService.indexKeyWord();
        List<MarketKeyword> hotKeywordList=map.get("hotkeywordList");
        List<MarketKeyword> defaultwordList=map.get("defaultKeyword");
        MarketKeyword marketDefaultKeyword=defaultwordList.get(0);
        Map<String,Object> data=new HashMap<>();
        data.put("defaultKeyword",marketDefaultKeyword);
        data.put("historyKeywordList",historyKeywordMap);
        data.put("hotKeywordList",hotKeywordList);
        return ResponseUtil.ok(data);

    }
    @GetMapping("helper")
    public Object helper(String keyword){
        List<String> list=wxSearchService.helper(keyword);
        return ResponseUtil.ok(list);
    }
    @PostMapping("clearhistory")
    public Object clearHistory(){
        Integer res=wxSearchService.clearhistory();

        if (res!=0){
            return ResponseUtil.ok();
        }
        return ResponseUtil.fail();

    }
}
